package com.yyfax.pay.third.model.to.quickpay;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.yyfax.framework.model.Content;
import com.yyfax.pay.third.model.to.quickpay.xml.ErrorMsgContent;

/**
 * 快钱响应实体父类
 * @author xiemh
 * @date 2017-04-12 14:56:35
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public abstract class BaseQuickPayContent extends Content{
	
	
	@XStreamAlias("ErrorMsgContent")
	private ErrorMsgContent errorMsgContent;
	
	private String reqUrl;
	
	private String reqContent;
	
	private String rspContent;
	
	

	public String getReqUrl() {
		return reqUrl;
	}

	public void setReqUrl(String reqUrl) {
		this.reqUrl = reqUrl;
	}

	public String getReqContent() {
		return reqContent;
	}

	public void setReqContent(String reqContent) {
		this.reqContent = reqContent;
	}

	
	
	public String getRspContent() {
		return rspContent;
	}

	public void setRspContent(String rspContent) {
		this.rspContent = rspContent;
	}

	public ErrorMsgContent getErrorMsgContent() {
		return errorMsgContent;
	}

	public void setErrorMsgContent(ErrorMsgContent errorMsgContent) {
		this.errorMsgContent = errorMsgContent;
	}	
	
	
	/**
	 * 实体对象转换成XML字符串
	 * 
	 * @author xiemh
	 * @date 2017-04-12 14:15:49
	 * @since v1.0.0
	 * @return
	 */
	public String toXml() {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("MasMessage", this.getClass());
		return xstream.toXML(this);
	}
	
	/**
	 * XML字符串转换成实体
	 * 
	 * @author xiemh
	 * @param <T>
	 * @date 2017-04-12 14:19:29
	 * @since v1.0.0
	 * @param xml
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected static <P extends BaseQuickPayContent> P fromXml(String xml,Class<P> p) {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("MasMessage", p);
		return (P) xstream.fromXML(xml);
	}
}
